import { loading } from '../loading/index';

const fs = require('fs');

export const log = (msg = 'no current command' , color = '\x1B[31m%s\x1B[0m') => {
	console.log(color, msg + '\n');
	loading.out();
	process.exit();
};

export const isExistFile = (cwd) => fs.existsSync(process.cwd() + '/' + cwd);

export const getWriteFile = (path) => {
	return fs.readFileSync(path);
};

export const setWriteFile = (path,packageJson) => {
	fs.writeFile(path, packageJson, function (err) {
		if (err) log('文件操作失败: error');
	});
};